#include <fstream>
#include "Input.h"
#include "PO_MoM.h"
#include "Modeling.h"
#include <iostream>
#include <cmath>
using namespace blitz;
void Initial()
{
	indata_PO();
	indata_MoM();
	SavingEdgeLength();
	SavingPatchCenterAndNormal();
	SavingT();
}

void indata_PO()
{
	std::ifstream geo("cube.dat");
	if (!geo)
	{
		std::cerr<<"file not open!"<<std::endl;
		exit(1);
	}

	geo>>iNode;
	vNode.resize(iNode);
	int ii;
	for (int i=0; i<iNode; i++)
	{
		geo>>ii>>vNode(i)[0]>>vNode(i)[1]>>vNode(i)[2];
	}

	geo>>iPatch;
	Patch.resize(iPatch,3);
	vPatchCtr.resize(iPatch);
	vPatchNorm.resize(iPatch);
	for (int i=0; i<iPatch; i++)
	{
		geo>>ii>>Patch(i,0)>>Patch(i,1)>>Patch(i,2);
	}
	Patch = Patch-1;

	geo>>iEdge;
	Edge.resize(iEdge,4);
	Edge_length.resize(iEdge);
	T.resize(iEdge);
	for (int i=0; i<iEdge; i++)
	{
		geo>>ii>>Edge(i,0)>>Edge(i,1)>>Edge(i,2)>>Edge(i,3);
	}
	Edge = Edge-1;
	geo.close();
}

void indata_MoM()
{
	std::ifstream geo("diapole.dat");
	if (!geo)
	{
		std::cerr<<"file not open!"<<std::endl;
		exit(1);
	}

	double sX,sY,sZ,eX,eY,eZ;
	geo>>iWire>>sX>>sY>>sZ>>eX>>eY>>eZ>>WireRadius;
	vWire.resize(iWire);
	Position3D vStartPoint(sX,sY,sZ),vEndPoint(eX,eY,eZ);
	Position3D Delta = (vEndPoint-vStartPoint)/(iWire+1);
	vStartPoint += 0.5*Delta;
	vEndPoint -= 0.5*Delta;
	DeltaLength = sqrt(dot(Delta,Delta));
	for (int i=0; i<iWire; i++)
		vWire(i) = vStartPoint+(i+0.5)*Delta;
	UnitVector = Delta/sqrt(dot(Delta,Delta));
	geo.close();
}
